package com.ly.hotel.spainterface.jyt.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.ly.hotel.R;
import com.ly.hotel.common.MyApplication;
import com.ly.hotel.spainterface.jyt.bean.MachineBean;
import com.ly.hotel.spainterface.jyt.bean.PluginBean;
import com.ly.hotel.spainterface.jyt.utils.JytXmlParseUtils;
import com.ly.hotel.spainterface.jyt.utils.MachineUtils;
import com.ly.hotel.spainterface.jyt.utils.OkHttpUtils;
import com.ly.hotel.util.ProcessWaitingUtil;
import com.ly.hotel.view.TitleLayout;
import com.ly.hotel.view.common.BaseActivity;

/**
 * Created by ThinkPad on 2018/3/31.
 */

public class JytJSActivity extends BaseActivity {

    private final String TAG = "JytJSActivity";
    private final int GET_TECHNICIAN_CATEGORY = 0;
    private MachineBean machineBean;
    private PluginBean pluginBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jyt_js_activity);
        getMachineInfo();
        getPluginConfig();
        initView();
        getTechnicianCategory();
    }

    // 获得电视相关信息
    public void getMachineInfo(){
        machineBean = MachineUtils.getHostAndTvInfo();
    }

    // 获取插件配置
    public void getPluginConfig(){
        Log.i(TAG,"插件版本：" + MyApplication.interfaceVersion);
        pluginBean = JytXmlParseUtils.getInstance().parseJishiPluginConfig(this, MyApplication.pluginCfg,MyApplication.interfaceVersion);
    }

    private void initView(){
        // 初始化标题栏
        TitleLayout titleLayout = findViewById(R.id.title_layout);
        TextView titleName = titleLayout.findViewById(R.id.activity_name);
        titleName.setTextColor(ContextCompat.getColor(this, R.color.mainWhite));
        titleName.setText(getResources().getString(R.string.naviJishiName));
    }

    private void getTechnicianCategory(){
        ProcessWaitingUtil.showProcessDialog(this,getResources().getString(R.string.loading_tips),10000);
        String url = "http://" + machineBean.getServerIP() + ":" + machineBean.getServerPORT() +
                "/api/tech-category.json";
        OkHttpUtils.getInstance().getTextResource(url,handler,GET_TECHNICIAN_CATEGORY);
    }


    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            String resultString = msg.obj.toString();
            Log.i(TAG,"接口返回：" + resultString);
            switch (msg.what){
                case 1:
                    ProcessWaitingUtil.closeProcessDialog();
                    if(msg.arg1 == GET_TECHNICIAN_CATEGORY){

                    }
                    break;

                case 2:

                    break;
            }
        }
    };
}
